fun main(args: Array<String>) {
    Parser.tokenizer("1--1").forEach { println(it) }
    Parser.toPostFix("1--1").forEach { println(it) }
    println(Evaluator.evaluate("1--1"))

    val evelDic = mutableMapOf<String, String>().apply {
        put("num1", "2")
        put("num2", "3")
    }
    var code = "r = num1 + num2;" +
            "r1 = r - -2;" +
            "r2 = r1 / 1;" +
            "r3 = r2 - 2;" +
            "r4 = (r - r2) * r3;"

    var r = code.split(';').map {
        var tmp = it.split('=')
        Pair(tmp.first(), tmp.last())
    }
    r.forEach {
        println(it.first)
        println(it.second)
        println("*******************************")
    }

    //解析计算
    r.forEach {
        var standardName = it.first.trim().toLowerCase()
        if (!evelDic.containsKey(standardName)) {
            var newFormula = ""
            Parser.tokenizer(it.second).forEach {
                newFormula += (if (evelDic.containsKey(it.trim().toLowerCase())) evelDic[it] else it) + " "
            }
            var result = Evaluator.evaluate(newFormula)
            evelDic[standardName] = result
            println("$standardName : [$newFormula]=$result")
        }

        println("*******************************")
    }
}